/*
 * Copyright(C) 2019 FUYUN DATA SERVICES CO.,LTD. - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited
 * Proprietary and confidential
 * 该源代码版权归属福韵数据服务有限公司所有
 * 未经授权，任何人不得复制、泄露、转载、使用，否则将视为侵权
 *
 */

import * as React from "react";
import { Layout, Avatar } from "antd";
import "./Header.scss";
import Cookies from "js-cookie";
import { resetAuthority } from "../../utils/authority";

const Container = Layout.Header;
interface IProps extends React.HTMLAttributes<HTMLDivElement> {
  contentClass?: string;
}

function handleExit() {
  Cookies.remove("user");
  Cookies.remove("user_role");
  resetAuthority();
  window.location.pathname = "/login";
}

function typeOfChange(value: any) {
  if (typeof value === "string") {
    return JSON.parse(value);
  }
}



const Header: React.SFC<IProps> = ({ style, className, contentClass }) => {
  const user: any = typeOfChange(Cookies.get("user"));
  return (
    <Container className={className} style={style}>
      <div className={"header-container " + contentClass}>
        <div className="logo" />
        <div className="headerSpan" />
        <ul className="action">
          <li>
            <Avatar size={24} icon="user" />
            <span style={{ margin: "20px" }}>{user.name}</span>
          </li>
          <li onClick={handleExit}>退出</li>
        </ul>
      </div>
    </Container>
  );
};

export default Header;
